//
//  FinishOrderViewController.m
//  OrderFood
//
//  Created by xiaofang wang on 2018/10/23.
//  Copyright © 2018年 zhiyuan. All rights reserved.
//

#import "FinishOrderViewController.h"
#import "BillCell.h"
@interface FinishOrderViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *billTableView;
@property(nonatomic,strong)NSMutableArray<OrderModel*> *dataSource;
@property(nonatomic,assign)NSInteger count;
@end

@implementation FinishOrderViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.name = @"已完成订单";
    self.count = 10;
    // 初始化UI
    [self setupUI];
}




// 初始化UI
- (void)setupUI{
    _dataSource = [NSMutableArray new];
    [self loadTableViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-SafeAreaTopHeight) tableViewStyle:UITableViewStylePlain refreshStyle:LSRefreshTypeJustHeader];
    self.mytableview.delegate = self;
    self.mytableview.dataSource = self;
    [self ls_headerBeginRefreshing];
}




- (void)requestNewData{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self netWorkFinshOrder];
    });
}
//- (void)requestMoreData{
//    if (self.count < 30) {
//        self.count+=10;
//        [self.mytableview reloadData];
//        [self ls_footerEndRefreshing];
//    }else{
//        [self.mytableview.mj_footer endRefreshingWithNoMoreData];
//    }
//
//}


-(void)netWorkFinshOrder {
    WeakObj(self)
    [NetWork netWorkFinishOrder:^(NSDictionary * _Nonnull response) {
        if (RES_SUCESS) {
            [weakself.dataSource removeAllObjects];
            for (NSDictionary *dic in [response objectForKey:@"data"]) {
                OrderModel *orderModel = [OrderModel new];
                [orderModel yy_modelSetWithJSON:dic];
                orderModel.orderId = [NSString stringWithFormat:@"%@", [dic objectForKey:@"id"]];
                [weakself.dataSource addObject:orderModel];
            }
            [weakself.mytableview reloadData];
        }else {
            [HUD showMessage:MESSAGE];
        }
        [self ls_headerEndRefreshing];
    } failure:^(NSString * _Nonnull message) {
        [HUD showMessage:FAIL_MESSAGE];
        [self ls_headerEndRefreshing];
    }];
}





#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"BillCellId";
    BillCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[BillCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.orderModel = [_dataSource objectAtIndex:indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 260;
}






@end
